'use strict';

const BaseController = require('./BaseController');
class LoginController extends BaseController {
  async index() {
 
  }
  async create() {
    const { ctx, app } = this;
    let user = {};
    user.username = ctx.request.body.username;
    user.password = ctx.request.body.password;
    if(user.username && user.password){
      try{
        const result = await ctx.model.User.findOne({
          where: user
        })
        if(result){
          result.role_authority = eval(result.role_authority)
          this.setUserInfo(result);
          console.log(result)
          ctx.body = {code:1,msg:"登录成功",data:result}
        }else{
          ctx.body = {code:0,msg:"用户名或密码错误"}
        }
      }catch(e){
        ctx.body = {code:0,msg:e}
      }
    }else{
      ctx.body = {code:0,msg:"请将信息填写完整！"}  
    }
  }
}

module.exports = LoginController;
